import  {createRouter,createWebHashHistory} from 'vue-router'

import Home from '@/components/home/index.vue'
import Login from '@/components/login/index.vue'
import TestPage from '@/components/mytest/testPage/index.vue'
import TestUseRooute1 from '@/components/mytest/testPage/testUseRoute/index1.vue'
import TestUseRooute2 from '@/components/mytest/testPage/testUseRoute/index2.vue'
import ColumnDetail from '@/components/ColumnDetail/ColumnDetail.vue'

import Signup from '@/components/Signup/Signup.vue'

import store from '@/store/index'

import CreatePost from '@/components/Post/CreatePost/CreatePost.vue'
const routerHistory = createWebHashHistory()
const router = createRouter({
    history: routerHistory,
    routes: [
        {
            path: '/',
            name: 'home',
            component: Home
        },
        {
            path: '/login',
            name: 'login',
            component: Login
        },
        {
            path: '/signup',
            name: 'signup',
            component: Signup
        },
        {
            path: '/test',
            name: 'test',
            component: TestPage
        },
        {
            path: '/useRoute1/:id',
            name: 'useRoute1',
            component: TestUseRooute1
        },
        {
            path: '/useRoute2/:id',
            name: 'useRoute2',
            component: TestUseRooute2
        },
        {
            path: '/columnDetail',
            name: 'columnDetail',
            component: ColumnDetail,
            meta: {
                UnAbleCreate: true
            }
        },
        {
            path: '/create',
            name: 'create',
            component: CreatePost,
            meta: {
                UnAbleCreate: true
            }
        }
    ]
})
router.beforeEach((to, from, next) => {
    if (to.meta && to.meta.UnAbleCreate) {
        store.commit('setUnAbleCreate',false)
    } else {
        store.commit('setUnAbleCreate',true)
    } 

     if ((to.name == 'create' && from.name == 'columnDetail')) {
        store.commit('setCurrentId',from.query.id)
    } else if ((to.name == 'create' && from.name == 'create')) {
        console.log('');
        
    } else {
        store.commit('setCurrentId',0)
    }
    next()
    
})

export default router